package com.easy.base.api.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.easy.base.api.model.dto.ResultBody;
import com.easy.base.api.model.enums.SessionAttrName;
import com.easy.base.api.utils.CaptchaUtil;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = { "verify" })
@RequestMapping("/api/verify")
@RestController
public class VerifyController {

    @Resource
    private HttpSession session;

    @ApiOperation(value = "登录验证码", nickname = "getLoginCaptcha")
    @GetMapping(value = "/login_captcha", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<ResultBody<String>> getLoginCaptcha() {
        String captcha = CaptchaUtil.Generator();
        session.setAttribute(SessionAttrName.LOGIN_CAPTCHA, captcha);
        session.setMaxInactiveInterval(60);
        return ResponseEntity.ok(ResultBody.Success(true, captcha));
    }

}
